//! 通过索引从数据中解析引用
//!
//! 需要传入的是 Vec<usize> 类型

/// 通过索引从数据中解析引用
///
/// ## Example
/// ```no_run
/// let pkg = Package;
/// let loader = Loader::from(pkg);
/// let package = loader.select_package(0)?;
/// let runner = package.create_runner(0)?;
///
/// let list = random_list!(0 => 50);
/// let cards = resolve_from!(@runner list => runner);
/// let cards2 = resolve_from!(@cards list => runner.cards);
/// ```
#[macro_export]
macro_rules! resolve_from {
    ($list:expr => $val:expr) => {{
        $list.iter().filter_map(|&index| $val.get(index)).collect()
    }};

    (@one $one:expr => $val:expr) => {{
        $val.get($one).unwrap()
    }};

    (@cards $list:expr => $cards:expr) => {{
        $list
            .iter()
            .filter_map(|&index| $cards.cards.get(index))
            .collect::<Vec<&::sgs_core::card::Card>>()
    }};
}
